<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <title></title>
    <meta charset="UTF-8">
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/bootstrap.css" />
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/bootstrap-responsive.css" />
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/style.css" />
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/bootstrap.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/ckform.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/common.js"></script>
    <script src="${pageContext.request.contextPath}/js/jquery.min.js?v=2.1.4"></script>
    <script src="${pageContext.request.contextPath}/js/date.js"></script>
    <style type="text/css">
        body {font-size: 20px;
            padding-bottom: 40px;
            background-color:#e9e7ef;
        }
        .sidebar-nav {
            padding: 9px 0;
        }

        @media (max-width: 980px) {
            /* Enable use of floated navbar text */
            .navbar-text.pull-right {
                float: none;
                padding-left: 5px;
                padding-right: 5px;
            }
        }
    </style>
    <script>

        $(function(){
            getUser();
        });

        function getUser(){

            var uname=$("#uname").val();
            $.ajax({
                url:"${pageContext.request.contextPath}/user/list",
                type:"POST",
                data:{"uname":uname},
                dataType:"json",
                cache:false,
                success:function(rs){
                    $("#tbody").empty();
                    $.each(rs.records,function(index,element){
                        var tr="<tr>\n" +
                                "<td style='display: none'>"+element.uid+"</td>"+
                            "           <td><a href=\"${pageContext.request.contextPath}/user/user_detail?uid="+element.uid+"\">"+element.uname+"</a></td>\n" +
                            "           <td>"+element.truename+"</td>\n" +
                            "           <td>"+element.email+"</td>\n" +
                            "           <td>"+get_date(element.utime)+"</td>\n" +
                            "           <td><button type=\"submit\" class=\"btnDelete\">注销</button></td>\n" +
                            "       </tr>";
                        $("#tbody").append(tr);
                    });

                }
            });
        }

        $(document).on("click",".btnDelete",function(event){

                var flag=window.confirm("您确定要删除吗");
                if(flag){
                    var uid=$(this).parents("tr").children().eq(0).text();
                    $.get("${pageContext.request.contextPath}/user/deleteUserById?uid="+uid,function(rs){

                        if(rs.status==200){
                            alert(rs.msg);
                            getUser();
                        }else if(rs.status==400){
                            alert(rs.msg);
                        }
                    },"json");
                }
        });
    </script>
</head>
<body>

<form id="form1" class="form-inline definewidth m20" action="#" method="get">
     <font color="#777777"><strong>用户名：</strong></font>
    <input type="text" name="uname" id="uname" class="abc input-default " placeholder="请填写用户名" value="">&nbsp;&nbsp;
    <button type="button" class="btn queryBtn" onclick="getUser();">查询</button>
</form>

<table id="usertable" class="table table-bordered table-hover definewidth m10">
    <thead>
    <tr>
        <th>用户名</th>
        <th>真实姓名</th>
        <th>Email</th>
        <th>注册日期</th>
        <th>冻结账户</th>
     </tr>
    </thead>
   <tbody id="tbody">


   </tbody>
</table>

</body>
</html>